/*
 * DoAnLyThuyet_JavaOutLookApp.java
 */

package doanlythuyet_javaoutlook;

import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import org.w3c.dom.*;
import org.xml.sax.SAXException;


/**
 * The main class of the application.
 */
public class DoAnLyThuyet_JavaOutLookApp extends SingleFrameApplication {
//proxy:
    private static String Curdir = System.getProperty("user.dir");
    private static String smtp_host;// = "smtp.gmail.com";
    private static String pop3_host;// = "pop.gmail.com";
    private static String user;// = "blueskyairlines05@gmail.com";
    private static String pass;// = "987412365";
    private static String proxy;// = "";
    private static String port;// = "";

    /**
     * @return the Curdir
     */
    public static String getCurdir() {
        return Curdir;
    }

    /**
     * @param aCurdir the Curdir to set
     */
    public static void setCurdir(String aCurdir) {
        Curdir = aCurdir;
    }

    /**
     * @return the smtp_host
     */
    public static String getSmtp_host() {
        return smtp_host;
    }

    /**
     * @param aSmtp_host the smtp_host to set
     */
    public static void setSmtp_host(String aSmtp_host) {
        smtp_host = aSmtp_host;
    }

    /**
     * @return the pop3_host
     */
    public static String getPop3_host() {
        return pop3_host;
    }

    /**
     * @param aPop3_host the pop3_host to set
     */
    public static void setPop3_host(String aPop3_host) {
        pop3_host = aPop3_host;
    }

    /**
     * @return the user
     */
    public static String getUser() {
        return user;
    }

    /**
     * @param aUser the user to set
     */
    public static void setUser(String aUser) {
        user = aUser;
    }

    /**
     * @return the pass
     */
    public static String getPass() {
        return pass;
    }

    /**
     * @param aPass the pass to set
     */
    public static void setPass(String aPass) {
        pass = aPass;
    }

    /**
     * @return the proxy
     */
    public static String getProxy() {
        return proxy;
    }

    /**
     * @param aProxy the proxy to set
     */
    public static void setProxy(String aProxy) {
        proxy = aProxy;
    }

    /**
     * @return the port
     */
    public static String getPort() {
        return port;
    }

    /**
     * @param aPort the port to set
     */
    public static void setPort(String aPort) {
        port = aPort;
    }

    public static void LayProxytuXML(String strFileName) throws SAXException{
          DocumentBuilderFactory factory = 	DocumentBuilderFactory.newInstance();
        DocumentBuilder builder;
        try {
            builder = factory.newDocumentBuilder();
            Document doc = builder.parse(new File(strFileName));
            Element root = 	(Element) doc.getDocumentElement();
            NodeList  nodelist = root.getElementsByTagName("Config");
            Element Ele = (Element)nodelist.item(0);
            NamedNodeMap attributes = Ele.getAttributes();
            for(int i=0;i<attributes.getLength();i++)
            {
                Node attributeNode = attributes.item(i);
                String name = attributeNode.getNodeName();
                String value = attributeNode.getNodeValue();
                if (name.equals("smtphost"))
                    smtp_host = value;
                if(name.equals("pop3host"))
                    pop3_host = value;
                if(name.equals("user"))
                    user = value;
                if(name.equals("pass"))
                    pass = value;
                if(name.equals("proxy"))
                    proxy = value;
                if(name.equals("port"))
                    port = value;

            }

        //String maSach = root.getAttribute("Inbox");



         Transformer xformer = TransformerFactory.newInstance().newTransformer();
         xformer.transform(new DOMSource(doc), new StreamResult(new File(strFileName)));

        } catch (ParserConfigurationException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookApp.class.getName()).log(Level.SEVERE, null, ex);
        }catch (SAXException ex) {
                Logger.getLogger(DoAnLyThuyet_JavaOutLookApp.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookApp.class.getName()).log(Level.SEVERE, null, ex);
        }catch (TransformerConfigurationException ex) {
                Logger.getLogger(DoAnLyThuyet_JavaOutLookApp.class.getName()).log(Level.SEVERE, null, ex);
        }catch (TransformerException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookApp.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        try {
            show(new DoAnLyThuyet_JavaOutLookView(this));
        } catch (SAXException ex) {
            Logger.getLogger(DoAnLyThuyet_JavaOutLookApp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of DoAnLyThuyet_JavaOutLookApp
     */
    public static DoAnLyThuyet_JavaOutLookApp getApplication() {
        return Application.getInstance(DoAnLyThuyet_JavaOutLookApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(DoAnLyThuyet_JavaOutLookApp.class, args);
    }
}
